<template>
  <view class="page">
    <block v-for="(item,index) in languages" :key="index">
      <view class="list-item solid-bottom" @click="handleToggle(item)">
        <text>{{item.title}}</text>
        <text class="cuIcon-check" v-if="item.type == cur"></text>
       <!-- <button :loading="item.loading" class="cu-btn" v-if="!item.default && !item.load" @click.stop="loadPackage(item,index)"></button> -->
      </view>
    </block>
  </view>
</template>

<script>
  // import fs from '@/common/utils/fs.js';
  import {LANGUAGES} from '@/common/config.js'
  export default {
    data(){
      return {
        languages: LANGUAGES,
        cur: '',
        caches: [], // 本地已有的资源包
      }
    },
    onLoad() {
			this.setNavigationBarTitle(this.i18n['语言'])
      this.init();
    },
    methods: {

      // 获取当前语言
      init(){
        this.cur = this.$i18n.locale;
      },
      // 切换语言
      async handleToggle(item){
        if(item.load == false) return ;
        let type = item.type;
        if(this.$i18n.locale === type) return ;
        this.$i18n.locale = type;
        this.cur = type;
        global.i18n = this.$i18n._vm.i18n;
        global.locale = this.$i18n.locale;
        this.setNavigationBarTitle(this.i18n['语言']);
        uni.setStorageSync('LANGUAGE_TYPE',type);
      },

    }
  }
</script>

<style lang="scss" scoped>
  .page{
    min-height: 100vh;
    background-color: #FFFFFF;
    padding: 0 32rpx;
    .list-item{
      height: 100rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;

    }
  }
  .tips{
    height: 100rpx;
    line-height: 100rpx;
    text-align: center;
    font-size: 24rpx;
    color: rgba(200,200,200,.6);
  }
</style>
